package com.lvhr.example.consumer;


import com.lvhr.example.common.model.User;
import com.lvhr.example.common.service.UserService;
import com.lvhr.rpc.RpcApplication;
import com.lvhr.rpc.config.RpcConfig;
import com.lvhr.rpc.constant.RpcConstant;
import com.lvhr.rpc.proxy.ServiceProxyFactory;
import com.lvhr.rpc.utils.ConfigUtils;

import java.util.Collections;

/**
 * 简易mock服务消费者示例
 */
public class EtcdConsumer {
    public static void main(String[] args) {
        RpcConfig rpc = ConfigUtils.loadConfig(RpcConfig.class,"rpc","", Collections.singletonList("properties"));
        RpcApplication.init(rpc);
        System.out.println(rpc.toString());

        // 获取代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("lv-rpc");
        // 调用
        for (int i = 0; i < 3 ; i++) {
            User newUser = userService.getUser(user);
            if (newUser != null) {
                System.out.println(newUser.getName());
            } else {
                System.out.println("user == null");
            }
        }

    }

}
